﻿using System;
using System.Web;

namespace KKCai.Utils.Web
{
    public static class MsgBoxHelper
    {
        public static void Alert(string message)
        {
            string script = string.Format("<script type=\"text/javascript\">alert(\"{0}\");</script>", message);

            HttpContext.Current.Response.Write(script);
        }

        public static void Confirm(string message, string url)
        {
            string script = "<script type=\"text/javascript\">var retValue=window.confirm('" + message + "');if(retValue){window.location.href='" + url + "';}</script>";

            HttpContext.Current.Response.Write(script);
        }

        public static void Location(string message, string url)
        {
            string script = string.Format("<script type=\"text/javascript\">alert(\"{0}\");window.location.href='{1}';</script>", message, url);

            HttpContext.Current.Response.Write(script);
        }

        public static void Location(string message, string url, string target)
        {
            string script = string.Format(String.Format("<script type=\"text/javascript\">alert(\"{{0}}\");{0}.location.href='{{1}}';</script>", target), message, url);

            HttpContext.Current.Response.Write(script);
        }

        public static void ReLoad()
        {
            string script = string.Format("<script type=\"text/javascript\">window.location.href=window.location.href;</script>");

            HttpContext.Current.Response.Write(script);
        }

        public static void Location(string url)
        {
            string script = string.Format("<script type=\"text/javascript\">window.location.href='{0}';</script>", url);

            HttpContext.Current.Response.Write(script);
        }

        public static void Close(string message)
        {
            string script = string.Format("<script type=\"text/javascript\">alert(\"{0}\");window.close();</script>", message);

            HttpContext.Current.Response.Write(script);
        }

        public static void Close()
        {
            string script = "<script type=\"text/javascript\">window.close();</script>";

            HttpContext.Current.Response.Write(script);
        }

        public static void GoBack(string message)
        {
            string script = string.Format("<script type=\"text/javascript\">alert(\"{0}\");history.go(-1);</script>", message);

            HttpContext.Current.Response.Write(script);
        }

        public static void GoBack()
        {
            string script = "<script type=\"text/javascript\">history.go(-1);</script>";

            HttpContext.Current.Response.Write(script);
        }
    }
}
